package com.toman.Util;

import android.Manifest;
import android.app.Activity;
import android.app.Application;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.util.TimeUtils;
import android.view.ContextThemeWrapper;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.haibin.calendarview.Calendar;
import com.haibin.calendarview.CalendarLayout;
import com.haibin.calendarview.CalendarView;
import com.lzy.okhttputils.OkHttpUtils;
import com.lzy.okhttputils.callback.StringCallback;
import com.toman.Dialog_Activity;
import com.toman.Interfaces.NewBaseUrl;
import com.toman.JavaBean.DeviceHouseMonthDayPlanEntity;
import com.toman.JavaBean.ImageObject;
import com.toman.MyApplication;
import com.toman.R;
import com.toman.bean.ItemBean;
import com.toman.bean.ItemListBean;
import com.toman.bean.TemplateInfBean;
import com.toman.camera.Camera;
import com.toman.camera.PreviewImgActivity;

import com.squareup.picasso.Picasso;
import com.toman.widget.callback.StringLoadingCallback;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import okhttp3.Request;
import okhttp3.Response;

import static com.toman.Util.DensityUtil.dip2px;
import static com.toman.Util.TimeUtil.thanTen;

/**
 * Created by 邹苏隆 on 2018/7/4.
 * description：
 */

public class ViewUtil {

    public static void unedit(EditText... editTexts) {
        for (EditText edit : editTexts) {
            edit.setBackgroundColor(Color.parseColor("#FFFFFF"));
            edit.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);

            edit.setFocusableInTouchMode(false);
            edit.setFocusable(false);
            edit.clearFocus();
            edit.setTextColor(Color.parseColor("#333333"));

        }
    }

    public static void visible(View... views) {
        for (View edit : views) {
            edit.setVisibility(View.VISIBLE);
        }
    }

    public static void gone(View... views) {
        for (View edit : views) {
            edit.setVisibility(View.GONE);
        }
    }

    public static void invisible(View... views) {
        for (View edit : views) {
            edit.setVisibility(View.INVISIBLE);
        }
    }

    public static boolean isNull(Context context, String[] item, TextView... views) {
        for (int i = 0; i < views.length; i++) {
            if (views[i].getText().toString().length() <= 0.) {
                ToastUtil.error(context, item[i] + "不得为空");
                return true;
            }
        }
        return false;

    }

    public static void necessary(TextView... views) {

            for (TextView view : views) {
                MyApplication myApplication;
                myApplication = MyApplication.getInstance();
                Drawable drawable = myApplication.getResources().getDrawable(R.mipmap.required);
                drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
//            view.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
//            view.setCompoundDrawablesWithIntrinsicBounds(null,null,drawable,null);
                view.setCompoundDrawables(null, null, drawable, null);

//            view.setTextAppearance(myApplication, R.style.et_edit_right_new);

            }


}

    /*比较大小*/
    public static boolean compareString(Context context, String[] item, TextView... views) {
        if (views.length != 2) {
            return true;
        }
        for (int i = 0; i < views.length; i++) {
            if (Integer.parseInt(views[0].getText().toString()) < Integer.parseInt(views[1].getText().toString())) {
                ToastUtil.makeText(context, item[0] + "不得小于" + item[1]);

                return true;
            }
        }
        return false;

    }


    public static void setText(String[] item, TextView... views) {
        for (int i = 0; i < views.length; i++) {
            views[i].setText(item[i]);
        }
    }

    public static void setText(Object[] item, TextView... views) {
        for (int i = 0; i < views.length; i++) {
            if (null == (item[i])) {

            } else {
                views[i].setText((String.valueOf(item[i])));
            }

        }

    }

    public static void setTextHide(Object[] item, TextView... views) {
        for (int i = 0; i < views.length; i++) {
            if (null == (item[i])) {
                View view = (View) views[i].getParent();
                view.setVisibility(View.GONE);
            }
            views[i].setText((String.valueOf(item[i])));

        }

    }

    public static void edit(EditText... editTexts) {
        MyApplication myApplication;
        myApplication = MyApplication.getInstance();
        for (EditText edit : editTexts) {
            edit.setBackgroundColor(Color.parseColor("#F0F0F5"));
            if (edit.getHeight() >= DensityUtil.dip2px(myApplication, 50)) {
                edit.setGravity(Gravity.LEFT);
                edit.setPadding(DensityUtil.dip2px(myApplication, 10), DensityUtil.dip2px(myApplication, 10), DensityUtil.dip2px(myApplication, 10), 10);
            } else {
                edit.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
            }
            edit.setFocusableInTouchMode(true);
            edit.setFocusable(true);
            edit.requestFocus();
//            edit.setTextColor(Color.parseColor("#333333"));


        }
    }

    public static void click(TextView... views) {
        for (TextView view : views) {
            view.setClickable(true);
            MyApplication myApplication;
            myApplication = MyApplication.getInstance();

            Drawable drawable = myApplication.getResources().getDrawable(R.mipmap.right);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
            view.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);

//            view.setCompoundDrawablesWithIntrinsicBounds(null,null,drawable,null);
            view.setCompoundDrawables(null, null, drawable, null);
            view.setHint("未选择");
            view.setTextColor(Color.parseColor("#333333"));
//            view.setTextAppearance(myApplication, R.style.et_edit_right_new);

        }
    }


    public static void unclick(TextView... views) {
        for (TextView view : views) {
            view.setClickable(false);
            view.setCompoundDrawables(null, null, null, null);
//            view.setTextColor(Color.parseColor("#999999"));


        }
    }

    public static void done(TextView... views) {
        for (TextView view : views) {
            view.setClickable(false);
            view.setCompoundDrawables(null, null, null, null);
//            view.setTextColor(Color.parseColor("#999999"));

        }
    }

    public static Camera createPhoto(String title, String[] url, Camera camera, Activity context, LinearLayout view, boolean show) {
        int margin = dip2px(context, 10);
        int etWidth = dip2px(context, 300);
        int h = dip2px(context, 1);
        RelativeLayout rl = new RelativeLayout(context);
        LinearLayout ll = new LinearLayout(context);
        TextView tv1 = new TextView(context);
        tv1.setText(title);
        tv1.setId(R.id.tv_code_title);
        tv1.setTextColor(Color.parseColor("#333333"));
        GridLayout gl_camara = new GridLayout(context);
        gl_camara.setBackgroundColor(context.getResources().getColor(R.color.white));
        camera = new Camera(context, gl_camara, show, 9);
        camera.showInternet(url);
        gl_camara.requestDisallowInterceptTouchEvent(true);
        tv1.setPadding(margin, margin, margin, margin);
        gl_camara.setPadding(2 * margin, margin, margin, margin);
        tv1.setBackgroundColor(context.getResources().getColor(R.color.white));
        view.addView(tv1);
        view.addView(gl_camara);
        return camera;
    }



    public static Camera createPhoto(String title, List<ImageObject> list, Camera camera, Activity context, LinearLayout view, boolean show) {
        String url[] = null;
        if (list != null) {
            url = new String[list.size()];
            for (int i = 0; i < url.length; i++) {
                url[i] = list.get(i).getImagePath();
            }
        }
        int margin = dip2px(context, 10);
        int etWidth = dip2px(context, 300);
        int h = dip2px(context, 1);
        RelativeLayout rl = new RelativeLayout(context);
        LinearLayout ll = new LinearLayout(context);
        TextView tv1 = new TextView(context);
        tv1.setText(title);
        tv1.setId(R.id.tv_code_title);
        tv1.setTextColor(Color.parseColor("#333333"));
        GridLayout gl_camara = new GridLayout(context);
        gl_camara.setBackgroundColor(context.getResources().getColor(R.color.white));
        camera = new Camera(context, gl_camara, show, 9);
        camera.showInternet(url);
        gl_camara.requestDisallowInterceptTouchEvent(true);
        tv1.setPadding(margin, margin, margin, margin);
        gl_camara.setPadding(2 * margin, margin, margin, margin);
        tv1.setBackgroundColor(context.getResources().getColor(R.color.white));
        view.addView(tv1);
        view.addView(gl_camara);
        return camera;
    }


//    public static Camera createPhoto(String title, List<ImageObject> list, Activity context, LinearLayout view, boolean show) {
//        String url[] = new String[list.size()];
//        for (int i = 0; i < url.length; i++) {
//            url[i] = list.get(i).getImagePath();
//        }
//Camera camera;
//        int margin = dip2px(context, 10);
//        int etWidth = dip2px(context, 300);
//        int h = dip2px(context, 1);
//        RelativeLayout rl = new RelativeLayout(context);
//        LinearLayout ll = new LinearLayout(context);
//        TextView tv1 = new TextView(context);
//        tv1.setText(title);
//        tv1.setId(R.id.tv_code_title);
//        tv1.setTextColor(Color.parseColor("#333333"));
//        GridLayout gl_camara = new GridLayout(context);
//        gl_camara.setBackgroundColor(context.getResources().getColor(R.color.white));
//        camera= new Camera(context, gl_camara, show, 9);
//        camera.showInternet(url);
//        gl_camara.requestDisallowInterceptTouchEvent(true);
//        tv1.setPadding(margin, margin, margin, margin);
//        gl_camara.setPadding(2 * margin, margin, margin, margin);
//        tv1.setBackgroundColor(context.getResources().getColor(R.color.white));
//        view.addView(tv1);
//        view.addView(gl_camara);
//        return  camera;
//    }

    public static Camera createPhoto(String title, List<ImageObject> list, Activity context, LinearLayout view, boolean show) {
        String url[] = null;
        if (list != null) {
            url = new String[list.size()];
            for (int i = 0; i < url.length; i++) {
                url[i] = list.get(i).getImagePath();
            }
        }
        Camera camera;
        int margin = dip2px(context, 10);
        int etWidth = dip2px(context, 300);
        int h = dip2px(context, 1);
        RelativeLayout rl = new RelativeLayout(context);
        LinearLayout ll = new LinearLayout(context);
        TextView textView = new TextView(new ContextThemeWrapper(context, R.style.tv_edit_left));
        RelativeLayout.LayoutParams rlParams =
                new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.MATCH_PARENT,
                        RelativeLayout.LayoutParams.WRAP_CONTENT);
        textView.setText(title);
        textView.setId(R.id.tv_code_title);
        rlParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        rlParams.addRule(RelativeLayout.CENTER_VERTICAL);
        textView.setPadding(DensityUtil.dip2px(context, 14), DensityUtil.dip2px(context, 6), 0, 0);
//        TextView tv1 = new TextView(context);
//        tv1.setText(title);
//        tv1.setId(R.id.tv_code_title);
        textView.setBackgroundColor(context.getResources().getColor(R.color.white));

//        tv1.setTextColor(Color.parseColor("#333333"));
        GridLayout gl_camara = new GridLayout(context);
        gl_camara.setBackgroundColor(context.getResources().getColor(R.color.white));
        camera = new Camera(context, gl_camara, show, 9);
        camera.showInternet(url);
        gl_camara.requestDisallowInterceptTouchEvent(true);

        gl_camara.setPadding(2 * margin, margin, margin, margin);
        view.addView(textView, rlParams);
        view.addView(gl_camara);
        return camera;
    }

    public static Camera createPhoto(String title, Camera camera, Activity context, LinearLayout view) {
        int margin = dip2px(context, 10);
        int etWidth = dip2px(context, 300);
        int h = dip2px(context, 1);
        RelativeLayout rl = new RelativeLayout(context);
        LinearLayout ll = new LinearLayout(context);
        TextView tv1 = new TextView(context);
        tv1.setText(title);
        tv1.setId(R.id.tv_code_title);
        tv1.setTextColor(Color.parseColor("#333333"));
        GridLayout gl_camara = new GridLayout(context);
        gl_camara.setBackgroundColor(context.getResources().getColor(R.color.white));
        camera = new Camera(context, gl_camara, false, 9);
        gl_camara.requestDisallowInterceptTouchEvent(true);
        tv1.setPadding(margin, margin, margin, margin);
        gl_camara.setPadding(2 * margin, margin, margin, margin);
        tv1.setBackgroundColor(context.getResources().getColor(R.color.white));
        view.addView(tv1);
        view.addView(gl_camara);
        return camera;
    }

    public static void getDateTime(final Context mContext, final TextView textView) {
        View date_time_picker = View.inflate(mContext, R.layout.date_time_picker, null);
        final DatePicker datePicker = (DatePicker) date_time_picker.findViewById(R.id.data_picker);
        final TimePicker timePicker = (TimePicker) date_time_picker.findViewById(R.id.timer_picker);
        timePicker.setVisibility(View.VISIBLE);

        timePicker.setIs24HourView(true);
        //   Build   DateTimeDialog
        final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setView(date_time_picker);
        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                int month = datePicker.getMonth() + 1;
                String dateStr = datePicker.getYear() + "-" + month + "-" + datePicker.getDayOfMonth();
                int currentMinute = timePicker.getCurrentMinute();
                String curMinute = "";
                if (currentMinute < 10) {
                    curMinute = "0" + currentMinute;
                } else {
                    curMinute = String.valueOf(currentMinute);
                }
                int currentHour = timePicker.getCurrentHour();
                String curHour = "";
                if (currentHour < 10) {
                    curHour = "0" + currentHour;
                } else {
                    curHour = String.valueOf(currentHour);
                }
                String timeStr = curHour + ":" + curMinute + ":00";
                if (!TimeUtil.compareNowTime(dateStr + " " + timeStr)) {
                    ToastUtil.makeText(mContext, "必须晚于现在的时间");
                    return;
                }

                textView.setText(dateStr + " " + timeStr);
            }
        });
        builder.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
        });
        builder.show();
    }
//    没有时间显示
    public static void getDateTimeNo(final Context mContext, final TextView textView) {
        View date_time_picker = View.inflate(mContext, R.layout.date_time_picker, null);
        final DatePicker datePicker = (DatePicker) date_time_picker.findViewById(R.id.data_picker);
        final TimePicker timePicker = (TimePicker) date_time_picker.findViewById(R.id.timer_picker);
        timePicker.setVisibility(View.VISIBLE);

        timePicker.setIs24HourView(true);
        //   Build   DateTimeDialog
        final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setView(date_time_picker);
        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                int month = datePicker.getMonth() + 1;
                String dateStr = datePicker.getYear() + "-" + month + "-" + datePicker.getDayOfMonth();
                int currentMinute = timePicker.getCurrentMinute();
                String curMinute = "";
                if (currentMinute < 10) {
                    curMinute = "0" + currentMinute;
                } else {
                    curMinute = String.valueOf(currentMinute);
                }
                int currentHour = timePicker.getCurrentHour();
                String curHour = "";
                if (currentHour < 10) {
                    curHour = "0" + currentHour;
                } else {
                    curHour = String.valueOf(currentHour);
                }
                String timeStr = curHour + ":" + curMinute + ":00";
                textView.setText(dateStr + " " + timeStr);

            }
        });
        builder.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
        });
        builder.show();
    }
    public static void getDate(final Context mContext, final TextView textView) {
        View date_time_picker = View.inflate(mContext, R.layout.date_picker, null);
        final DatePicker datePicker = (DatePicker) date_time_picker.findViewById(R.id.data_picker);


        //   Build   DateTimeDialog
        final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setView(date_time_picker);
        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                int month = datePicker.getMonth() + 1;
                String m, d;
                if (month < 10) {
                    m = "0" + month;
                } else {
                    m = "" + month;
                }
                if (datePicker.getDayOfMonth() < 10) {
                    d = "0" + datePicker.getDayOfMonth();
                } else {
                    d = "" + datePicker.getDayOfMonth();
                }
                String dateStr = datePicker.getYear() + "-" + m + "-" + d;
                textView.setText(dateStr);
            }
        });
        builder.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
        });
        builder.show();
    }
    public static void getDate(final Context mContext, final TextView textView , ActionCallback callback) {
        View date_time_picker = View.inflate(mContext, R.layout.date_picker, null);
        final DatePicker datePicker = (DatePicker) date_time_picker.findViewById(R.id.data_picker);


        //   Build   DateTimeDialog
        final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setView(date_time_picker);
        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                int month = datePicker.getMonth() + 1;
                String m, d;
                if (month < 10) {
                    m = "0" + month;
                } else {
                    m = "" + month;
                }
                if (datePicker.getDayOfMonth() < 10) {
                    d = "0" + datePicker.getDayOfMonth();
                } else {
                    d = "" + datePicker.getDayOfMonth();
                }
                String dateStr = datePicker.getYear() + "-" + m + "-" + d;
                textView.setText(dateStr);
                callback.run();
            }
        });
        builder.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
        });
        builder.show();
    }



    public static void getMonth(final Context mContext, final TextView textView) {
        View date_time_picker = View.inflate(mContext, R.layout.date_picker, null);
        final DatePicker datePicker = (DatePicker) date_time_picker.findViewById(R.id.data_picker);


        //   Build   DateTimeDialog
        final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setView(date_time_picker);
        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                int month = datePicker.getMonth() + 1;
                String m, d;
                if (month < 10) {
                    m = "0" + month;
                } else {
                    m = "" + month;
                }
                if (datePicker.getDayOfMonth() < 10) {
                    d = "0" + datePicker.getDayOfMonth();
                } else {
                    d = "" + datePicker.getDayOfMonth();
                }
                String dateStr = datePicker.getYear() + "-" + m + "-" + d;
                textView.setText(dateStr);
            }
        });
        builder.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
        });
        builder.show();
    }

    public static AlertDialog.Builder getdays(final Context mContext, String token, List<DeviceHouseMonthDayPlanEntity> list, final TextView textView, boolean isHorizontalScrollBarEnabled, ActionCallback callback) {
        View days_picker = View.inflate(mContext, R.layout.days_picker, null);
        final List<Calendar> schemes = new ArrayList<>();
        TextView mTextMonthDay;

        TextView mTextYear;

        TextView mTextLunar;

        TextView mTextCurrentDay;

        CalendarView mCalendarView;

        RelativeLayout mRelativeTool;
        int mYear;
        final int[] nYear = new int[2];
        final int[] cYear = new int[2];
        int nMonth;
        CalendarLayout mCalendarLayout;
        mCalendarLayout = (CalendarLayout) days_picker.findViewById(R.id.calendarLayout);

        mTextMonthDay = (TextView) days_picker.findViewById(R.id.tv_month_day);
        mTextYear = (TextView) days_picker.findViewById(R.id.tv_year);
        mTextLunar = (TextView) days_picker.findViewById(R.id.tv_lunar);
        mRelativeTool = (RelativeLayout) days_picker.findViewById(R.id.rl_tool);
        mCalendarView = (CalendarView) days_picker.findViewById(R.id.calendarView);
        mTextCurrentDay = (TextView) days_picker.findViewById(R.id.tv_current_day);
        mYear = mCalendarView.getCurYear();
        nMonth = mCalendarView.getCurMonth();
        mCalendarView.setHorizontalScrollBarEnabled(isHorizontalScrollBarEnabled);
        mTextMonthDay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!mCalendarLayout.isExpand()) {
                    mCalendarView.showYearSelectLayout(mYear);
                    return;
                }
                mCalendarView.showYearSelectLayout(mYear);
                mTextLunar.setVisibility(View.GONE);
                mTextYear.setVisibility(View.GONE);
                mTextMonthDay.setText(String.valueOf(mYear));
            }
        });
        days_picker.findViewById(R.id.fl_current).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCalendarView.scrollToCurrent();
            }
        });

        mCalendarView.setOnYearChangeListener(new CalendarView.OnYearChangeListener() {
            @Override
            public void onYearChange(int year) {
                mTextMonthDay.setText(String.valueOf(year));
            }
        });
        mCalendarView.setOnDateSelectedListener(new CalendarView.OnDateSelectedListener() {
            @Override
            public void onDateSelected(Calendar calendar, boolean isClick) {
                mTextLunar.setVisibility(View.VISIBLE);
                mTextYear.setVisibility(View.VISIBLE);
                mTextMonthDay.setText(calendar.getMonth() + "月" + calendar.getDay() + "日");
                mTextYear.setText(String.valueOf(calendar.getYear()));
                mTextLunar.setText(calendar.getLunar());


//        Toast.makeText(this, "长按不选择日期\n" + getCalendarText(calendar), Toast.LENGTH_SHORT).show();
                if (schemes.contains(getSchemeCalendar(calendar.getYear(), calendar.getMonth(), calendar.getDay(), 0xFF13acf0, "工"))) {
                    schemes.remove(getSchemeCalendar(calendar.getYear(), calendar.getMonth(), calendar.getDay(), 0xFF13acf0, "工"));
                } else {
                    schemes.add(getSchemeCalendar(calendar.getYear(), calendar.getMonth(), calendar.getDay(), 0xFF13acf0, "工"));
                }

                mCalendarView.setSchemeDate(schemes);
            }
        });
//mCalendarView.setRange(2018,11,2018,12);
        mCalendarView.setOnMonthChangeListener(new CalendarView.OnMonthChangeListener() {
            @Override
            public void onMonthChange(int year, int month) {
                mTextMonthDay.setText(String.valueOf(year + "年" + month + "月"));
                nYear[0] = year;
                nYear[1] = month;
                if ((cYear[1] == month) && list.size() != 0) {
                    schemes.clear();
                    for (int i = 0; i < list.size(); i++) {
                        DeviceHouseMonthDayPlanEntity entity = list.get(i);
                        java.util.Calendar calendar = TimeUtil.StringToCalendar(entity.getDay());
                        schemes.add(getSchemeCalendar(calendar.get(java.util.Calendar.YEAR), calendar.get(java.util.Calendar.MONTH) + 1, calendar.get(java.util.Calendar.DAY_OF_MONTH), 0xFF13acf0, "工"));
                    }

                    mCalendarView.setSchemeDate(schemes);
                } else {
                    getWorkdayByMonth(token, year, month, mCalendarView, schemes);
                }
            }
        });
        if (list.size() != 0) {
            DeviceHouseMonthDayPlanEntity entity1 = list.get(0);
            java.util.Calendar calendar1 = TimeUtil.StringToCalendar(entity1.getDay());
            cYear[1] = calendar1.get(java.util.Calendar.MONTH) + 1;
            if (!isHorizontalScrollBarEnabled) {
                mCalendarView.setRange(calendar1.get(java.util.Calendar.YEAR), calendar1.get(java.util.Calendar.MONTH) + 1, calendar1.get(java.util.Calendar.YEAR), calendar1.get(java.util.Calendar.MONTH) + 1);
            }
            mCalendarView.scrollToCalendar(calendar1.get(java.util.Calendar.YEAR), calendar1.get(java.util.Calendar.MONTH) + 1, 1);
        }
        mCalendarView.setSchemeDate(schemes);
//        mCalendarView.setOnDateLongClickListener(new, true);
        mTextYear.setText(String.valueOf(mCalendarView.getCurYear()));
        mTextMonthDay.setText(mCalendarView.getCurMonth() + "月" + mCalendarView.getCurDay() + "日");
        mTextLunar.setText("今日");
        mTextCurrentDay.setText(String.valueOf(mCalendarView.getCurDay()));
        days_picker.findViewById(R.id.fl_current).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCalendarView.scrollToCurrent();
            }
        });


        //   Build   DateTimeDialog
        final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setView(days_picker);
        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                List<DeviceHouseMonthDayPlanEntity> copyed = new ArrayList<>(list);
                list.clear();
                for (Calendar calendar : schemes) {
                    StringBuilder days = new StringBuilder();

                    days.append(calendar.getYear()).append("-").append(thanTen(calendar.getMonth())).append("-").append(thanTen(calendar.getDay()));
                    DeviceHouseMonthDayPlanEntity bean = new DeviceHouseMonthDayPlanEntity();
                    bean.setDay(days.toString());
                    bean.setPlanOutput(0);
                    if (!copyed.contains(bean)) {
                        list.add(bean);
                    } else {
                        list.add(copyed.get(copyed.indexOf(bean)));
                    }
                }
                if (!list.isEmpty()) {
                    Collections.sort(list, new Comparator<DeviceHouseMonthDayPlanEntity>() {
                        @Override
                        public int compare(DeviceHouseMonthDayPlanEntity o1, DeviceHouseMonthDayPlanEntity o2) {
                            return o1.getDay().compareTo(o2.getDay());
                        }
                    });
                }

                textView.setText(nYear[0] + "-" + nYear[1]);
                callback.run();
            }
        });
        builder.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
        });
        builder.show();
        return builder;
    }

    public static List<Calendar> getWorkdayByMonth(String token, int year, int month, CalendarView mCalendarView, List<Calendar> schemes) {
//        List<Calendar> schemes = new ArrayList<>();
        StringBuilder days = new StringBuilder();
        days.append(year).append("-").append(thanTen(month));
        OkHttpUtils
                .get(NewBaseUrl.workday_getworkdaybymonth)
                .params("token", token)
                .params("month", days.toString())

                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", "工作日: " + result);


                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");
                        if (code == 0) {

                            List<String> jsonArray = new ArrayList<>(JSONArray.parseArray(jsonObj.getString("workDay"), String.class));
                            schemes.clear();
                            for (int i = 0; i < jsonArray.size(); i++) {
                                String days = jsonArray.get(i);

                                schemes.add(getSchemeCalendar(year, month, TimeUtil.StringToCalendar(days).get(java.util.Calendar.DAY_OF_MONTH), 0xFF13acf0, "工"));
                            }
                            mCalendarView.setSchemeDate(schemes);

                        } else {
//                        ToastUtil.makeText(getApplicationContext(), jsonObj.getString("msg"));
                        }


                    }
                });
        return schemes;

    }

    //获取已安排的工作日
    public static AlertDialog.Builder getdays2(final Context mContext, String token, String dep, List<DeviceHouseMonthDayPlanEntity> list, final TextView textView, boolean isHorizontalScrollBarEnabled, ActionCallback callback) {
        View days_picker = View.inflate(mContext, R.layout.days_picker, null);
        final List<Calendar> schemes = new ArrayList<>();
        List<DeviceHouseMonthDayPlanEntity> workdays = new ArrayList<>();

        TextView mTextMonthDay;

        TextView mTextYear;

        TextView mTextLunar;

        TextView mTextCurrentDay;

        CalendarView mCalendarView;

        RelativeLayout mRelativeTool;
        int mYear;
        final int[] nYear = new int[2];
        final int[] cYear = new int[2];
        int nMonth;
        CalendarLayout mCalendarLayout;
        mCalendarLayout = (CalendarLayout) days_picker.findViewById(R.id.calendarLayout);

        mTextMonthDay = (TextView) days_picker.findViewById(R.id.tv_month_day);
        mTextYear = (TextView) days_picker.findViewById(R.id.tv_year);
        mTextLunar = (TextView) days_picker.findViewById(R.id.tv_lunar);
        mRelativeTool = (RelativeLayout) days_picker.findViewById(R.id.rl_tool);
        mCalendarView = (CalendarView) days_picker.findViewById(R.id.calendarView);
        mTextCurrentDay = (TextView) days_picker.findViewById(R.id.tv_current_day);
        mYear = mCalendarView.getCurYear();
        nMonth = mCalendarView.getCurMonth();
        mCalendarView.setHorizontalScrollBarEnabled(isHorizontalScrollBarEnabled);
        mTextMonthDay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!mCalendarLayout.isExpand()) {
                    mCalendarView.showYearSelectLayout(mYear);
                    return;
                }
                mCalendarView.showYearSelectLayout(mYear);
                mTextLunar.setVisibility(View.GONE);
                mTextYear.setVisibility(View.GONE);
                mTextMonthDay.setText(String.valueOf(mYear));
            }
        });
        days_picker.findViewById(R.id.fl_current).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCalendarView.scrollToCurrent();
            }
        });

        mCalendarView.setOnYearChangeListener(new CalendarView.OnYearChangeListener() {
            @Override
            public void onYearChange(int year) {
                mTextMonthDay.setText(String.valueOf(year));
            }
        });
        mCalendarView.setOnDateSelectedListener(new CalendarView.OnDateSelectedListener() {
            @Override
            public void onDateSelected(Calendar calendar, boolean isClick) {
                mTextLunar.setVisibility(View.VISIBLE);
                mTextYear.setVisibility(View.VISIBLE);
                mTextMonthDay.setText(calendar.getMonth() + "月" + calendar.getDay() + "日");
                mTextYear.setText(String.valueOf(calendar.getYear()));
                mTextLunar.setText(calendar.getLunar());


//        Toast.makeText(this, "长按不选择日期\n" + getCalendarText(calendar), Toast.LENGTH_SHORT).show();
                if (schemes.contains(getSchemeCalendar(calendar.getYear(), calendar.getMonth(), calendar.getDay(), 0xFF13acf0, "工"))) {
                    schemes.remove(getSchemeCalendar(calendar.getYear(), calendar.getMonth(), calendar.getDay(), 0xFF13acf0, "工"));
                } else {
                    schemes.add(getSchemeCalendar(calendar.getYear(), calendar.getMonth(), calendar.getDay(), 0xFF13acf0, "工"));
                }

                mCalendarView.setSchemeDate(schemes);
            }
        });
//mCalendarView.setRange(2018,11,2018,12);
        mCalendarView.setOnMonthChangeListener(new CalendarView.OnMonthChangeListener() {
            @Override
            public void onMonthChange(int year, int month) {
                mTextMonthDay.setText(String.valueOf(year + "年" + month + "月"));
                schemes.clear();
                nYear[0] = year;
                nYear[1] = month;
                if ((cYear[1] == month) && list.size() != 0) {

                    for (int i = 0; i < list.size(); i++) {
                        DeviceHouseMonthDayPlanEntity entity = list.get(i);
                        java.util.Calendar calendar = TimeUtil.StringToCalendar(entity.getDay());
                        schemes.add(getSchemeCalendar(calendar.get(java.util.Calendar.YEAR), calendar.get(java.util.Calendar.MONTH) + 1, calendar.get(java.util.Calendar.DAY_OF_MONTH), 0xFF13acf0, "工"));
                    }
                    mCalendarView.setSchemeDate(schemes);
                }
//获取工作
                getWorkdayPlanByMonth(mContext, token, dep, year, month, workdays);

            }
        });
        if (list.size() != 0) {
            DeviceHouseMonthDayPlanEntity entity1 = list.get(0);
            java.util.Calendar calendar1 = TimeUtil.StringToCalendar(entity1.getDay());
            cYear[1] = calendar1.get(java.util.Calendar.MONTH) + 1;
            if (!isHorizontalScrollBarEnabled) {
                mCalendarView.setRange(calendar1.get(java.util.Calendar.YEAR), calendar1.get(java.util.Calendar.MONTH) + 1, calendar1.get(java.util.Calendar.YEAR), calendar1.get(java.util.Calendar.MONTH) + 1);
            }
            mCalendarView.scrollToCalendar(calendar1.get(java.util.Calendar.YEAR), calendar1.get(java.util.Calendar.MONTH) + 1, 1);
        }
        mCalendarView.setSchemeDate(schemes);
//        mCalendarView.setOnDateLongClickListener(new, true);
        mTextYear.setText(String.valueOf(mCalendarView.getCurYear()));
        mTextMonthDay.setText(mCalendarView.getCurMonth() + "月" + mCalendarView.getCurDay() + "日");
        mTextLunar.setText("今日");
        mTextCurrentDay.setText(String.valueOf(mCalendarView.getCurDay()));
        days_picker.findViewById(R.id.fl_current).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCalendarView.scrollToCurrent();
            }
        });


        //   Build   DateTimeDialog
        final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setView(days_picker);
        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                List<DeviceHouseMonthDayPlanEntity> copyed = new ArrayList<>(list);
                list.clear();
                for (Calendar calendar : schemes) {
                    StringBuilder days = new StringBuilder();

                    days.append(calendar.getYear()).append("-").append(thanTen(calendar.getMonth())).append("-").append(thanTen(calendar.getDay()));
                    DeviceHouseMonthDayPlanEntity bean = new DeviceHouseMonthDayPlanEntity();
                    bean.setDay(days.toString());
                    bean.setPlanOutput(0);
                    if (!copyed.contains(bean)) {
                        list.add(bean);
                    } else {
                        list.add(copyed.get(copyed.indexOf(bean)));
                    }
                }
                if (!list.isEmpty()) {
                    Collections.sort(list, new Comparator<DeviceHouseMonthDayPlanEntity>() {
                        @Override
                        public int compare(DeviceHouseMonthDayPlanEntity o1, DeviceHouseMonthDayPlanEntity o2) {
                            return o1.getDay().compareTo(o2.getDay());
                        }
                    });
                }

                StringBuilder days = new StringBuilder();
                for (DeviceHouseMonthDayPlanEntity entity : list) {
                    if (days.length() <= 0) {
                        days.append(entity.getDay());
                    } else {
                        days.append(",").append(entity.getDay());
                    }
                }


//                textView.setText(days.toString());
                callback.run(list.containsAll(workdays));
            }
        });
        builder.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
        });
        builder.show();
        return builder;
    }


    public static void getWorkdayPlanByMonth(Context context, String token, String dep, int year, int month, List<DeviceHouseMonthDayPlanEntity> list) {
//        List<Calendar> schemes = new ArrayList<>();
        StringBuilder days = new StringBuilder();
        days.append(year).append("-").append(thanTen(month));

            OkHttpUtils
                    .get(NewBaseUrl.devicehousemonthplan_appselectlist)
                    .params("token", token)
                    .params("month", days.toString())
                    .params("departmentId", dep)

                    .execute(new StringCallback() {
                        @Override
                        public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                            Log.i("test", "工作日: " + result);


                            JSONObject jsonObj = JSON.parseObject(result);
                            int code = jsonObj.getInteger("code");
                            if (code == 0) {

                                List<DeviceHouseMonthDayPlanEntity> jsonArray = new ArrayList<DeviceHouseMonthDayPlanEntity>(JsonExcludeNull.parseArrayExcludeNull(jsonObj.getString("list"), DeviceHouseMonthDayPlanEntity.class));
                                list.addAll(jsonArray);

                            } else {
                                ToastUtil.makeText(context, jsonObj.getString("msg"));
                            }


                        }
                    });


        }



    private static Calendar getSchemeCalendar(int year, int month, int day, int color, String text) {
        Calendar calendar = new Calendar();
        calendar.setYear(year);
        calendar.setMonth(month);
        calendar.setDay(day);
        calendar.setSchemeColor(color);//如果单独标记颜色、则会使用这个颜色
        calendar.setScheme(text);
        return calendar;
    }


    //    选择时间
    public static void getTime(Context mContext, final TextView textView) {
        View date_time_picker = View.inflate(mContext, R.layout.time_picker, null);
        final TimePicker timePicker = (TimePicker) date_time_picker.findViewById(R.id.timer_picker);

        timePicker.setIs24HourView(true);
        //   Build   DateTimeDialog
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setView(date_time_picker);
        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                int currentMinute = timePicker.getCurrentMinute();
                int currentHour=timePicker.getCurrentHour();
                String curMinute = "";
                String curHour = "";
                if (currentMinute < 10) {
                    curMinute = "0" + currentMinute;
                } else {
                    curMinute = String.valueOf(currentMinute);
                }
                if (currentHour < 10) {
                    curHour = "0" + currentHour;
                } else {
                    curHour = String.valueOf(currentHour);
                }


                String timeStr = curHour + ":" + curMinute;
                ToastUtil.print(timeStr);
                textView.setText(timeStr);
            }
        });
        builder.setNegativeButton("清除", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                textView.setText(null);
            }
        });
        builder.show();
    }

    public static void insertURL(final String text1, final String[] imgurl, final Activity context, LinearLayout ll) {
//        10dp的默认margin
        int margin = dip2px(context, 10);
        int h = dip2px(context, 1);
        int h1 = dip2px(context, 100);
        int h2 = dip2px(context, 30);
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
//        获取当前屏幕的宽度
        int width = wm.getDefaultDisplay().getWidth() - 2 * margin;
        int height = wm.getDefaultDisplay().getHeight();
//        计算一个图片所占的宽度
        int left = (width - 2 * margin) / 3;

//图片的父控件相对布rl
        RelativeLayout rl = new RelativeLayout(context);
        rl.setPadding(margin, margin, margin, margin);
//        图片的标题
        TextView tv1 = new TextView(context);
        tv1.setText(text1);
        tv1.setId(R.id.tv_code_title);
        RelativeLayout.LayoutParams rlParams =
                new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.MATCH_PARENT,
                        RelativeLayout.LayoutParams.WRAP_CONTENT);
        RelativeLayout.LayoutParams tvParams1 =
                new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT,
                        RelativeLayout.LayoutParams.WRAP_CONTENT);
        tvParams1.addRule(RelativeLayout.ALIGN_PARENT_LEFT, tv1.getId());
        rl.addView(tv1, tvParams1);
//for循环插入不同位置的图片
        for (int j = 0; j < imgurl.length; j++) {
            final int num = j;
//            计算图片在第几层
            int x = (int) Math.floor(j / 3);
//            计算图片在第几个位置
            int y = j % 3;
            ImageView img = new ImageView(context);
            img.setId(R.id.tv_code_img + j);
            Picasso.with(context).load(imgurl[j]).error(R.mipmap.ic_launcher).into(img);
            RelativeLayout.LayoutParams imgParams1 =
                    new RelativeLayout.LayoutParams(
                            h1, h1);
//            img.setScaleType(ImageView.ScaleType.FIT_START);
            img.setScaleType(ImageView.ScaleType.CENTER_CROP);

            imgParams1.addRule(RelativeLayout.BELOW, tv1.getId());
//            设置图片相对父控件的位置
            imgParams1.leftMargin = (y + 1) * margin + y * left;
            imgParams1.topMargin = (x + 2) * margin + x * left;
            //注册上下文菜单
//            将图片设置到RL父控件中去
            rl.addView(img, imgParams1);
            img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent();
                    intent.putExtra("imgpath", imgurl[num]);
                    intent.setClass(context, PreviewImgActivity.class);
                    context.startActivity(intent);
                }
            });


        }
        rl.setBackgroundColor(0xffffff);
//        把RL父控件加到总控件ll中去
        ll.addView(rl, rlParams);
        View view = new View(context);
//        view.setBackgroundColor(getColor(R.color.line_gray));
        RelativeLayout.LayoutParams vParams =
                new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.MATCH_PARENT,
                        h);
        ll.addView(view, vParams);
    }


    /*
        设置未开启权限dialog
     */
    public static void Dialog(final Context context) {
        final android.app.AlertDialog dialog = new android.app.AlertDialog.Builder(context).create();
        dialog.show();
        dialog.getWindow().setContentView(R.layout.location_dialog1);
        dialog.setCanceledOnTouchOutside(false);

        dialog.getWindow().findViewById(R.id.exit1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });

        dialog.getWindow().findViewById(R.id.go_set1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
//                intent.setData(Uri.parse("package:" + context.this.getPackageName()));
                context.startActivity(intent);
            }
        });

    }

    public static void hide(LinearLayout ll_child, ImageView imageView) {
        if (ll_child.getVisibility() == View.VISIBLE) {
            ll_child.setVisibility(View.GONE);
            imageView.setImageResource(R.mipmap.down);
        } else {
            ll_child.setVisibility(View.VISIBLE);
            imageView.setImageResource(R.mipmap.upward);
        }

    }
    public static void hideReport(View ll_child, TextView textView) {
        if (ll_child.getVisibility() == View.VISIBLE) {
            ll_child.setVisibility(View.GONE);
            Drawable drawable = MyApplication.getInstance().getResources().getDrawable(R.mipmap.report_icon_arrows);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
            textView.setCompoundDrawables(null, null, drawable, null);

        } else {
            ll_child.setVisibility(View.VISIBLE);
            Drawable drawable = MyApplication.getInstance().getResources().getDrawable(R.mipmap.report_icon_arrows_up);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
            textView.setCompoundDrawables(null, null, drawable, null);
        }

    }
    public static void hideView(View view) {
        if (view.getVisibility() == View.VISIBLE) {
            view.setVisibility(View.GONE);
        } else {
            view.setVisibility(View.VISIBLE);
        }
    }

    public static void hideView(View... views) {
        for (View view : views) {
            if (view.getVisibility() == View.VISIBLE) {
                view.setVisibility(View.GONE);
            } else {
                view.setVisibility(View.VISIBLE);
            }
        }
    }


    // 判断是否开启相机权限
    public static boolean checkPer(Activity context) {
        if ((ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)) {
            ActivityCompat.requestPermissions(context, new String[]{Manifest.permission.CAMERA}, 1002);
            return false;
        }
        return true;
    }

    //    强制登出
    public static void lagout(int code, Context context) {
        if (code == 401) {
            Intent mIntent = new Intent(context, Dialog_Activity.class);
            mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(mIntent);
        }
    }

    public static void permission(Context context, String key, View view) {
        if (PermissonUtils.contains(context, key)) {
        } else {
            view.setVisibility(View.GONE);
        }
    }

    public static void permissionNew(Context context, String key, View view) {

        if (PermissonUtils.contains(context, key)) {
            view.setVisibility(View.VISIBLE);

        } else {
            view.setVisibility(View.GONE);
        }
    }
    public static void permissionNew(Context context, String key, List list,View view) {

        if (PermissonUtils.contains(context, key)&&list.size()!=0) {
            view.setVisibility(View.VISIBLE);

        } else {
            view.setVisibility(View.GONE);
        }
    }

    public static <T> String getMutiCheck(List<T> list) {
        if (list == null || list.size() <= 0) {
            return null;
        }
        try {
            T t = list.get(0);
            Field field = t.getClass().getDeclaredField("checkStatus");
            Field fieldId = t.getClass().getDeclaredField("id");
            field.setAccessible(true);
            fieldId.setAccessible(true);
            StringBuilder stringBuffer = new StringBuilder();
            for (int i = 0; i < list.size(); i++) {

                if ((Boolean) field.get(list.get(i))) {
                    if (stringBuffer.length() <= 0) {
                        stringBuffer.append(fieldId.get(list.get(i)));
                    } else {
                        stringBuffer.append(",").append(fieldId.get(list.get(i)));
                    }
                }
            }
            if (stringBuffer.length() <= 0) {
                return null;
            } else {
                return stringBuffer.toString();
            }
        } catch (Exception e) {
            return null;
        }
    }

    public static <T> String getPreviewHot(List<T> list) {
        if (list == null || list.size() <= 0) {
            return null;
        }
        try {
            T t = list.get(0);
            Field field = t.getClass().getDeclaredField("selected");
            Field fieldId = t.getClass().getDeclaredField("terminalId");
            field.setAccessible(true);
            fieldId.setAccessible(true);
            StringBuilder stringBuffer = new StringBuilder();
            for (int i = 0; i < list.size(); i++) {

                if ((Boolean) field.get(list.get(i))) {
                    if (stringBuffer.length() <= 0) {
                        stringBuffer.append(fieldId.get(list.get(i)));
                    } else {
                        stringBuffer.append(",").append(fieldId.get(list.get(i)));
                    }
                }
            }
            if (stringBuffer.length() <= 0) {
                return null;
            } else {
                return stringBuffer.toString();
            }
        } catch (Exception e) {
            return null;
        }
    }


    public static String getDeleteUrl(Camera camera) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < camera.getDeleteUrl().size(); i++) {
            if (stringBuilder.length() <= 0) {
                stringBuilder.append(camera.getDeleteUrl().get(i));
            } else {
                stringBuilder.append(",").append(camera.getDeleteUrl().get(i));
            }
        }
        return stringBuilder.toString();
    }


    public static List<File> getFiles(Camera camera) {
        List<String> list = camera.getCompressUrl();
        List<File> files = new ArrayList<>();
        for (String path : list) {
            File file = new File(path);
            files.add(file);
        }
        return files;
    }
//无权限，则停止
    public static boolean hasPermiison(Context context,String permiison) {
        if (!PermissonUtils.contains(context, permiison)) {
            ToastUtil.makeText(context,"暂无"+permiison+"权限，请联系管理员");
            return true;
        }
        return false;
    }

    /**
     * 判断是否是全面屏
     */
    private volatile static boolean mHasCheckAllScreen;
    private volatile static boolean mIsAllScreenDevice;

    public static boolean isAllScreenDevice(Context context) {
        if (mHasCheckAllScreen) {
            return mIsAllScreenDevice;
        }
        mHasCheckAllScreen = true;
        mIsAllScreenDevice = false;
        // 低于 API 21的，都不会是全面屏。。。
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            return false;
        }
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        if (windowManager != null) {
            Display display = windowManager.getDefaultDisplay();
            Point point = new Point();
            display.getRealSize(point);
            float width, height;
            if (point.x < point.y) {
                width = point.x;
                height = point.y;
            } else {
                width = point.y;
                height = point.x;
            }
            if (height / width >= 1.97f) {
                mIsAllScreenDevice = true;
            }
        }
        return mIsAllScreenDevice;
    }

}
